/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "country")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Country.findAll", query = "SELECT c FROM Country c"),
    @NamedQuery(name = "Country.findByIdCountry", query = "SELECT c FROM Country c WHERE c.idCountry = :idCountry"),
    @NamedQuery(name = "Country.findByDescription", query = "SELECT c FROM Country c WHERE c.description = :description")})
public class Country implements Serializable, Comparable<Country>, InternationalizableEntity {
    @OneToMany(mappedBy = "country", fetch = FetchType.LAZY)
    private List<Company> companyList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", fetch = FetchType.LAZY)
    private List<SearchRelocatingInfoRequerimentAndOperator> searchRelocatingInfoRequerimentAndOperatorList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", fetch = FetchType.LAZY)
    private List<SearchRelocatingInfoRequerimentOrOperator> searchRelocatingInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "offerCountry", fetch = FetchType.LAZY)
    private List<Search> searchList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", fetch = FetchType.LAZY)
    private List<CandidateRelocatingInfo> candidateRelocatingInfoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCountry", fetch = FetchType.LAZY)
    private List<CountryDescription> countryDescriptionList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_COUNTRY")
    private Integer idCountry;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", fetch = FetchType.LAZY)
    private List<Province> provinceList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", fetch = FetchType.LAZY)
    private List<Candidate> candidateList;

    public Country() {
    }

    public Country(Integer idCountry) {
        this.idCountry = idCountry;
    }

    public Country(Integer idCountry, String description) {
        this.idCountry = idCountry;
        this.description = description;
    }

    public Integer getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(Integer idCountry) {
        this.idCountry = idCountry;
    }

    @Override
    public String getDescription() {
        return description;
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getCountryDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(CountryDescription cd:getCountryDescriptionList()){
//                if(cd.getIdLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<Province> getProvinceList() {
        return provinceList;
    }

    public void setProvinceList(List<Province> provinceList) {
        this.provinceList = provinceList;
    }

    @XmlTransient
    public List<Candidate> getCandidateList() {
        return candidateList;
    }

    public void setCandidateList(List<Candidate> candidateList) {
        this.candidateList = candidateList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCountry != null ? idCountry.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Country)) {
            return false;
        }
        Country other = (Country) object;
        if ((this.idCountry == null && other.idCountry != null) || (this.idCountry != null && !this.idCountry.equals(other.idCountry))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Country[ idCountry=" + idCountry + " ]";
    }

    @XmlTransient
    public List<CountryDescription> getCountryDescriptionList() {
        return countryDescriptionList;
    }

    public void setCountryDescriptionList(List<CountryDescription> countryDescriptionList) {
        this.countryDescriptionList = countryDescriptionList;
    }

    @XmlTransient
    public List<CandidateRelocatingInfo> getCandidateRelocatingInfoList() {
        return candidateRelocatingInfoList;
    }

    public void setCandidateRelocatingInfoList(List<CandidateRelocatingInfo> candidateRelocatingInfoList) {
        this.candidateRelocatingInfoList = candidateRelocatingInfoList;
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @XmlTransient
    public List<SearchRelocatingInfoRequerimentAndOperator> getSearchRelocatingInfoRequerimentAndOperatorList() {
        return searchRelocatingInfoRequerimentAndOperatorList;
    }

    public void setSearchRelocatingInfoRequerimentAndOperatorList(List<SearchRelocatingInfoRequerimentAndOperator> searchRelocatingInfoRequerimentAndOperatorList) {
        this.searchRelocatingInfoRequerimentAndOperatorList = searchRelocatingInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchRelocatingInfoRequerimentOrOperator> getSearchRelocatingInfoRequerimentOrOperatorList() {
        return searchRelocatingInfoRequerimentOrOperatorList;
    }

    public void setSearchRelocatingInfoRequerimentOrOperatorList(List<SearchRelocatingInfoRequerimentOrOperator> searchRelocatingInfoRequerimentOrOperatorList) {
        this.searchRelocatingInfoRequerimentOrOperatorList = searchRelocatingInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<Company> getCompanyList() {
        return companyList;
    }

    public void setCompanyList(List<Company> companyList) {
        this.companyList = companyList;
    }

    @Override
    public int compareTo(Country c) {
        return this.getDescription().compareTo(c.getDescription());
    }

    @Override
    public Integer getId() {
        return getIdCountry();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getCountryDescriptionList();
    }
    
}
